﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Benefit.Service.ServerData
{
    /// <summary>
    /// 平台上面的客户
    /// </summary>
    public class ServiceT_Custome : Benefit.Interface.ServerData.IT_Custome
    {
        Benefit.DB.DBManager db = null;
        public ServiceT_Custome(Benefit.DB.DBManager db)
        {
            this.db = db;
        }

        public List<Models.ServerData.T_Custome> GetList()
        {
            DavidDB.ADO.DBManager dbmanager = new DavidDB.ADO.DBManager();
            List<Models.ServerData.T_Custome> customes = new List<Models.ServerData.T_Custome>();
            string sql = "select * from T_Custome";
            dynamic sdr = dbmanager.ExecuteReader(sql);
            while (sdr.Read())
            {
                Models.ServerData.T_Custome c = new Models.ServerData.T_Custome();
                c.Address = sdr["Address"].ToString();
                c.BankAccount = sdr["BankAccount"].ToString();
                c.BankId = Convert.ToInt32(sdr["BankId"]);
                c.Credentials_Type = sdr["Credentials_Type"].ToString();
                c.Id = Convert.ToInt32(sdr["Id"]);
                c.CustomeName = sdr["CustomeName"].ToString();
                c.Email = sdr["Email"].ToString();
                c.IDCard = sdr["IDCard"].ToString();
                c.Mobile = sdr["Mobile"].ToString();
                c.Photo = sdr["Photo"].ToString();
                c.Telphone = sdr["Telphone"].ToString();
                c.Type = sdr["Type"].ToString();
                c.Zipcode = sdr["Zipcode"].ToString();
                customes.Add(c);
            }
            sdr.Close();
            dbmanager.Commit();
            dbmanager.Dispose();
            return customes;
        }

        public List<Models.ServerData.T_Custome> GetUnRegistCustomes()
        {
            List<Models.ServerData.T_Custome> customes = this.GetList();
            List<Models.ServerData.T_Custome> unRegistCustomes = new List<Models.ServerData.T_Custome>();
            var query = from t in db.Operators select t;
            List<Models.Sys.Operator> operators = query.ToList();
            foreach (Models.ServerData.T_Custome c in customes)
            {
                bool isExist = false;
                var query2 = from t in operators where c.CustomeName.Equals(t.UName) select t;
                if (query2.Count() > 0)
                {
                    isExist = true;
                }
                if (!isExist)
                {
                    unRegistCustomes.Add(c);
                }
            }
            return unRegistCustomes;
        }
    }
}